<template>
	<view class="bg-white">
		<cu-custom bgImage="https://image.weilanwl.com/color2.0/plugin/wdh2236.jpg" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">申请授权</block>
		</cu-custom>
		
		<view>
			<form @submit="postData">
				<view class="cu-form-group ">
					<view class="title">您购买的模块</view>
					<picker @change="PickerChange" :value="index" :range="list" range-key="name">
						<view class="picker">
							{{index>-1?list[index]['name']:'选择模块'}}
						</view>
					</picker>
				</view>
				<view class="cu-form-group ">
					<view class="title">站点名称</view>
					<input placeholder="您的微擎站点名称" name="name"></input>
				</view>
				<view class="cu-form-group">
					<view class="title">微擎域名</view>
					<input placeholder="您的微擎域名" name="site"></input>
				</view>
				<view class="cu-form-group">
					<view class="title">订单号</view>
					<input placeholder="您的模块购买订单号" name="ordersn"></input>
				</view>
				
				<view class="padding" style="margin-top: 50px;">
					<button form-type="submit" class="cu-btn block lg bg-theme">提交</button>
				</view>
				
			</form>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				picker: ['喵喵喵', '汪汪汪', '哼唧哼唧'],
				list:[],
				index:-1
			}
		},
		onLoad() {
			this.getmodules()
		},
		methods: {
			PickerChange(e){
				this.index = e.detail.value
			},
			getmodules(){
				this.util.csAjax('/addons/open/wxapp.open/module',{},(ret)=>{
					console.log(ret)
					this.list = ret.data
				})
			},
			postData(e){
				console.log(e)
				if(this.index<0){
					return this.$api.msg('请选择模块')
				}
				var data = e.detail.value
				data['openmodule_id'] = this.list[this.index].id
				
				this.util.csAjax('/addons/open/wxapp.open/authapply',data,(ret)=>{
					console.log(ret)
					uni.navigateBack({
						
					})
				})
				
			}
		}
	}
</script>

<style>
	page{
		background-color: #FFFFFF;
	}
</style>
